#include "uhm/common.hxx"
#include "uhm/util.hxx"
#include "uhm/discrete/base/mesh.hxx"

#define N 1

using namespace uhm;

typedef ID_Node_<N>             Id_Nd;
typedef ID_Element_<N>          Id_El;
typedef Mesh_<Id_Nd,Id_El,Int_> Mesh;

int main (int argc, char **argv) {

  Mesh::_Id_El_ el;
  el.set_id(0,  10); Mesh::Element_ element_p(el);
  el.set_id(0, 100); Mesh::Element_ element_a(el);
  el.set_id(0, 200); Mesh::Element_ element_b(el);


  std::cout << element_p << "\n"
            << element_a << "\n"
            << element_b << "\n";

  Mesh::_Id_Nd_ nd;

  nd.set_id(0, 10); Mesh::Node_ node_a(nd);
  nd.set_id(0, 20); Mesh::Node_ node_b(nd);
  nd.set_id(0, 30); Mesh::Node_ node_c(nd);
  nd.set_id(0, 40); Mesh::Node_ node_d(nd);

  element_a.push_begin();
  element_a.push(&node_a);
  element_a.push(&node_b);
  element_a.push(&node_c);
  element_a.push_end();

  element_b.push_begin();
  element_b.push(&node_b);
  element_b.push(&node_c);
  element_b.push(&node_d);
  element_b.push_end();

  std::cout << "** Element a and b has nodes\n";
  std::cout << element_p << "\n"
            << element_a << "\n"
            << element_b << "\n";

  element_a.separate();
  element_b.separate();

  std::cout << "** Element should be separated by now\n";
  std::cout << element_p << "\n"
            << element_a << "\n"
            << element_b << "\n";

  element_p.update(&element_a);
  element_p.update(&element_b);

  std::cout << "** Element a and b update parent p\n";
  std::cout << element_p << "\n"
            << element_a << "\n"
            << element_b << "\n";

  element_p.separate();

  std::cout << "** Element a, b, and p are separated\n";
  std::cout << element_p << "\n"
            << element_a << "\n"
            << element_b << "\n";

  std::cout << "** Now nodes have no owner\n";
  std::cout << node_a << "\n"
            << node_b << "\n"
            << node_c << "\n"
            << node_d << "\n";

  return true;
}


